//
//  ZYVisitorLoginView.swift
//  ZYSinaWeibo
//
//  Created by 陟岳 on 16/5/26.
//  Copyright © 2016年 陟岳. All rights reserved.
//

import UIKit
import SnapKit

class ZYVisitorLoginView: UIView {
    
    
    //重写初始化方法
    override init(frame: CGRect) {
        super.init(frame:frame)
        self.setupUI() 
        startAnimation()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func startAnimation() {
    
        //基本动画
        let basicAnm = CABasicAnimation(keyPath: "transform.rotation")
        basicAnm.duration = 15
        basicAnm.repeatCount = MAXFLOAT
        basicAnm.toValue = M_PI * 2
        basicAnm.removedOnCompletion = false
        
        circleIcon.layer.addAnimation(basicAnm, forKey: nil)
    
    }

    //设置UI界面
    private func setupUI() {
    
        addSubview(circleIcon)
        addSubview(tipLabel)
        addSubview(backIcon)
        addSubview(largeHouse)
        addSubview(loginBtn)
        addSubview(registBtn)
    

        //自动布局子控件
        circleIcon.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        
        largeHouse.snp_makeConstraints { (make) in
            make.center.equalTo(self.circleIcon.snp_center)
        }
        
        tipLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(self.snp_centerX)
            make.top.equalTo(circleIcon.snp_bottom)
        }
        
        loginBtn.snp_makeConstraints { (make) in
            make.left.equalTo(tipLabel.snp_left)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        
        registBtn.snp_makeConstraints { (make) in
            make.right.equalTo(tipLabel.snp_right)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        backIcon.snp_makeConstraints { (make) in
            make.center.equalTo(circleIcon.snp_center)
        }
        //一般使用sRGB取值
        let value: CGFloat = 237.0 / 255.0
        backgroundColor = UIColor(red: value, green: value, blue: value, alpha: 1)
        
        
    }
   
    //懒加载子视图
    //遮罩图片
    private lazy var backIcon: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))

    private lazy var circleIcon: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    private lazy var largeHouse: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    private lazy var tipLabel: UILabel = {
    
        let l = UILabel()
        
        l.text = "关注一些人,回到这里看看有什么惊喜"
        l.textColor = UIColor.grayColor()
        l.font = UIFont.systemFontOfSize(14)
        l.sizeToFit()
        
        return l
    }()
    
    
    private lazy var loginBtn: UIButton = {
    
        let loginBtn = UIButton()
        loginBtn.setTitle("登录", forState: .Normal)
        loginBtn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        
        loginBtn.titleLabel?.font = UIFont.systemFontOfSize(15)
        loginBtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        
        return loginBtn
        
    
    }()
    
    private lazy var registBtn: UIButton = {
        
        let registBtn = UIButton()
        registBtn.setTitle("注册", forState: .Normal)
        registBtn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        
        registBtn.titleLabel?.font = UIFont.systemFontOfSize(15)
        registBtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        
        return registBtn
        
        
    }()
}
